package net.midnighttd.engine.entity;

import java.util.LinkedList;

/**
 * Author: Adam Scarr
 * Date: 23/04/2009
 * Time: 8:25:45 PM
 */
public class EntityList extends LinkedList<Entity> {
    public EntityList(EntityList peg) {
        super(peg);
    }

    public EntityList() {
        super();
    }

    /**
     * @param type Entity type
     * @return The first entity of the given type, or null if it dosent exist.
     */
    public Entity getFirst(String type) {
        for(Entity e: this) {
            if(e.getType().equals(type)) return e;
        }

        return null;
    }

    /**
     * @param type The entity type.
     * @param type The entity type.
     * @return All entities of a given type, or an empty list if none exist.
     */
    public EntityList get(String type) {
        EntityList entList = new EntityList();

        for(Entity e: this) {
            if(e.getType().equals(type)) entList.add(e);
        }

        return entList;
    }
}
